<template>
	<view class="">
		<uni-popup ref="popup" type="bottom" background-color="#fff" borderRadius="20rpx 20rpx 0 0">
			<view class="popup-wrap">
				<view class="popup-header">
					<view class="popup-header-close" @click="close">
						<text>取消</text>
					</view>
					<view class="popup-header-title">
						<text>{{ title }}</text>
					</view>
					<view class="popup-header-confirm" @click="confirm">
						<text>确定</text>
					</view>
				</view>
				<view class="popup-content">
					<view class="popup-content-list">
						<picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value"
							@change="bindChange" class="picker-view">
							<!-- <picker-view-column>
								<view class="item" :class="{'item-active': year == item}" v-for="(item,index) in years" :key="index">{{item}}年</view>
							</picker-view-column> -->
							<!-- <picker-view-column>
								<view class="item" :class="{'item-active': month == item}" v-for="(item,index) in months" :key="index">{{item}}月</view>
							</picker-view-column>
							<picker-view-column>
								<view class="item" :class="{'item-active': day == item}" v-for="(item,index) in days" :key="index">{{item}}日</view>
							</picker-view-column> -->
							
							<picker-view-column>
								<view class="item" :class="{'item-active': value[0] == index}" v-for="(item,index) in daysArr" :key="index">{{item.data}}</view>
							</picker-view-column>
							<picker-view-column>
								<view class="item" :class="{'item-active': value[1] == index}" v-for="(item,index) in hours" :key="index">{{item.data}}</view>
							</picker-view-column>
							<picker-view-column>
								<view class="item" :class="{'item-active': value[2] == index}" v-for="(item,index) in minutes" :key="index">{{item.data}}</view>
							</picker-view-column>
						</picker-view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		props: {
			title: {
				type: String,
				default: ""
			}
		},
		data() {
			const date = new Date()
			const years = []
			const year = date.getFullYear()
			const months = []
			const month = date.getMonth() + 1
			const days = []
			const day = date.getDate()
			for (let i = 1990; i <= date.getFullYear(); i++) {
				years.push(i)
			}
			for (let i = 1; i <= 12; i++) {
				months.push(i)
			}
			for (let i = 1; i <= 31; i++) {
				days.push(i)
			}
			
			let n_hours = date.getHours()
			let hours = []
			for (let i = 0; i<= 23; i++){
				hours.push({
					value:i,
					data:i+'点'
				})
			}
			
			let now_minetus = ''
			let m = date.getMinutes()
			let minutes = []
			for (let i = 0; i<= 5; i++){
				minutes.push({
					value:i*10,
					data:(i*10)+'分'
				})
				if(m>=(i*10)&&m<50){
					now_minetus = i + 1
				}else if(m>=50){
					now_minetus = 0
				}
			}
			
			return {
				years,
				year,
				months,
				month,
				days,
				day,
				// value: [9999, month - 1, day - 1],
				value: [0, n_hours, now_minetus],
				visible: true,
				indicatorStyle: `height: 96rpx;`,
				
				daysArr:[
					{
						value:1,
						data:'今天',
					},
					{
						value:2,
						data:'明天'
					}
				],
				
				hours,
				minutes,
			}
		},
		methods: {
			open() {
				this.$refs.popup.open()
			},

			close() {
				this.$refs.popup.close()
			},

			confirm() {
				let date = ''
				if(this.value[0]==0){
					date = this.$dayjs().format('YYYY-MM-DD')
				}else{
					date = this.$dayjs().add(1, 'day').format('YYYY-MM-DD')
				}
				
				let times = ''
				let hours = ''
				if(this.hours[this.value[1]].value<=9){
					hours = '0'+this.hours[this.value[1]].value
				}else{
					hours = this.hours[this.value[1]].value
				}
				let minutes = ''
				if(this.minutes[this.value[2]].value<=9){
					minutes = '0'+this.minutes[this.value[2]].value
				}else{
					minutes = this.minutes[this.value[2]].value
				}
				times = hours+':'+minutes
				this.$emit("confirm", date+' '+times)
				this.close()
			},
			bindChange: function(e) {
				const val = e.detail.value
				// this.year = this.years[val[0]]
				// this.month = this.months[val[1]]
				// this.day = this.days[val[2]]
				this.value = val
			}
		}
	}
</script>

<style scoped lang="scss">
	.popup-wrap {
		padding: 36rpx 0rpx 68rpx 0rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.popup-header {
		display: flex;
		align-items: center;
		padding: 0 22rpx;
	}

	.popup-header-title {
		flex: 1;
		text-align: center;
		font-weight: bold;
		font-size: 36rpx;
		color: #333333;
	}

	.popup-header-close {
		// position: absolute;
		font-weight: 400;
		font-size: 32rpx;
		color: #999999;
	}

	.popup-header-confirm {
		font-weight: bold;
		font-size: 32rpx;
		color: #E72A2A;
	}

	.popup-content {
		margin-top: 46rpx;
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.popup-content-list {
		height: 788rpx;
	}

	.picker-view {
		width: 750rpx;
		height: 600rpx;
		margin-top: 20rpx;
	}

	.item {
		// line-height: 96rpx;
		line-height: 64rpx;
		text-align: center;
		font-weight: 400;
		font-size: 32rpx;
		color: #999999;
	}
	
	.item-active {
		color: #E72A2A;
		background-color: #FFF2F2;
	}
</style>